#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct msgbuf
{
    long type;
    char voltage[124];
    char ID[4];
};

int main()
{
    int msgid;
    struct msgbuf sendbuf;
    struct msgbuf recvbuf;
    msgid = msgget(IPC_PRIVATE, 0777);
    sendbuf.type = 100;
    printf("please input message:\n");
    fgets(sendbuf.voltage, 124, stdin);
    msgsnd(msgid, (void *)&sendbuf, strlen(sendbuf.voltage), 0);

    memset(recvbuf.voltage,0,124);

// error
    int readret = msgrcv(msgid, (void *)&recvbuf, 124, 100, 0);
    printf("recv len = %d, recv: %s", readret, recvbuf.voltage);
    memset(sendbuf.voltage,0,124);

// error
    int readret = msgrcv(msgid, (void *)&sendbuf, 124, 100, 0);
    printf("recv len = %d, recv: %s", readret, sendbuf.voltage);
    msgctl(msgid, IPC_RMID, NULL);



}
